

library(tidyverse)
library(rio)

# set replication folder as working directory
setwd("~replication")

load("data_genderedcost_background.rdata")

# only include completed answers - and answers given before deadline
# 2021-12-20 21:49:52 was the last response within the time frame
df_background <- df_background %>% 
  filter(SurveyStatus==2)

df_background <- df_background %>% 
  filter(SurveyEndTime<="2021-12-20 21:49:52")

##### Assessed risk of sexual harassment
sample_shares <- df_background %>%
  count(harassment_risk) %>% 
  mutate(prop_risk = prop.table(n)) %>% 
  mutate(sex = factor("Full Sample"))

subset_shares <- df_background %>%
  filter(harassment_risk!="Do not know") %>% 
  count(sex, harassment_risk) %>% 
  group_by(sex) %>% 
  mutate(prop_risk = prop.table(n)) %>% 
  mutate(sex = factor(ifelse(sex=="Man","Men","Women")))

shares <- bind_rows(sample_shares, subset_shares)

shares %>%
  filter(harassment_risk!="Do not know") %>% 
  ggplot(data=., aes(x=harassment_risk, y=prop_risk, fill = sex)) +
  geom_col(color = "black", position = position_dodge2(width = 0.2)) +
  theme_bw() +
  labs(y = "Share", x = "") +
  xlab("Self-assessed risk of victimization of sexual harassment in political work") +
  scale_fill_grey("") +
  scale_color_grey("") +
  geom_text(aes(label = round(prop_risk,digits = 2)),
            position = position_dodge(width = 0.9), vjust = -0.5, size = 3) +
  scale_y_continuous(labels = seq(0,0.7,0.1), breaks = seq(0,0.7,0.1)) +
  theme(legend.position = "right",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank())

ggsave("figure2.pdf", height = 4, width = 8)
ggsave("figure2.png", height = 4, width = 8, dpi = 600)
